package com.dr.java.day04;

/**
 * Created by rui on 2017/12/29.
 */
public class FindMaxAndMin {
    public static void main(String[] args) {
        int[] arr = {5, 1, 6, 4, 2, 8, 9};
        System.out.println(
                findMax(arr)
        );
        System.out.println(findMin(arr));
    }

    private static int findMin(int[] arr) {
        int min = arr[0];
        for (int i : arr) {
            if (min > i) {
                min = i;
            }
        }
        return min;
    }

    private static int findMax(int[] arr) {
        int max = arr[0];
        for (int i : arr) {
            if (max < i) {
                max = i;
            }
        }
        return max;
    }
}
